//package com.example.springboot_jdk8.util;
//
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.http.webservice.SoapClient;
//import cn.hutool.json.JSONArray;
//import cn.hutool.json.JSONObject;
//import cn.hutool.json.JSONUtil;
//import cn.hutool.json.XML;
//import com.example.springboot_jdk8.config.CacheCurConfig;
//import com.example.springboot_jdk8.config.MdmConfig;
//import com.example.springboot_jdk8.enums.PullDataConfigEnum;
//import lombok.extern.slf4j.Slf4j;
//
//import javax.xml.soap.SOAPElement;
//import javax.xml.soap.SOAPException;
//import javax.xml.soap.SOAPHeader;
//import java.util.*;
//import java.util.stream.Collectors;
//
//
///**
// * @author chenli
// */
//@Slf4j
//public class MdmRequestUtil {
//
//
//    /**
//     * 封装统一对外获取所有组织的方法
//     */
////    public static List<JSONObject> getAllOrg() {
////        //1.获取所有分部(公司）
////        JSONArray allOrgs = getOrgs();
////        List<JSONObject> orgJsonObjList = allOrgs.stream().map(object -> (JSONObject) object).collect(Collectors.toList());
////        //全量可在内存中组装路径和层级
////        loopDeptPathAndLevel(orgJsonObjList);
////        return  orgJsonObjList.stream()
////                .filter(orgInfo -> StrUtil.isNotEmpty(orgInfo.getStr("level")))
////                .sorted(Comparator.comparingInt((jsonObj)-> jsonObj.getInt("level")))
////                        .collect(Collectors.toList());
////    }
//
//
//
//    /**
//     * 分页查询所有组织
//     * @return
//     */
//    public static JSONArray getOrgs(Map<String, Object> extParam) {
//        log.info("==== 分页查询所有公司 start ====");
//        MdmConfig config = CacheCurConfig.getConfig();
//        JSONArray allOrgs = new JSONArray(100);
//        HashMap<String, Object> requestDataMap = new HashMap<>();
//        Integer curPage = 1;
//        requestDataMap.put("pageIndex", curPage);
//        requestDataMap.put("pageSize", 50);
//        requestDataMap.putAll(extParam);
//        String requestData = "";
//        JSONObject respBody = null;
//        boolean hasNext = false;
//        do {
//            requestData = MdmUtil.buildReqData(JSONUtil.toJsonStr(requestDataMap));
//            respBody = MdmUtil.request(requestData, config.getDomain() + config.getOrgUrl());
//            //将数据添加进集合返回
//            allOrgs.addAll(respBody.getJSONArray("dataList"));
//            hasNext = respBody.getBool("nextPagee");
//            Integer pageTotal = respBody.getInt("pageTotal");
//            if (pageTotal != null && curPage > pageTotal) {
//                break;
//            }
//            //增加页码,下次循环重新计算hash
//            requestDataMap.put("pageIndex", curPage++);
//        } while (hasNext);
//        return allOrgs;
//    }
//
//
//    /**
//     * 分页查询所有部门
//     *
//     * @return
//     */
//    public static List<JSONObject> getAllDept(MdmConfig mdmConfig) {
//        log.info("==== 分页查询所有部门 start ====");
//        ArrayList<JSONObject> allDept = new ArrayList<>();
////        SoapClient soapClient = SoapClient.create(mdmConfig.getWebServiceTargetUrl())
////                .setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl())
////                .timeout(mdmConfig.getTimeOutSecond() * 1000);
////        int page = 1;
////        buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.DEPT_CONFIG_ID.getValue(), mdmConfig);
////        String send = soapClient.send(true);
////        JSONObject jsonObject = parseResp(send);
////        allDept.addAll(extractValueList(jsonObject));
////        Boolean hasNextPage = jsonObject.getBool("hasNextPage");
////        log.info("==== 获取全部部门是否有下一页： {} ,当前第 {} 页 ====", hasNextPage, page);
////        while (hasNextPage) {
////            page++;
////            BizException.throwWhenTrueMessage(page > mdmConfig.getLoopMaxThreshold(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrCode(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrMsg() + ":" + mdmConfig.getLoopMaxThreshold());
////            soapClient.reset();
////            soapClient.setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl()).timeout(mdmConfig.getTimeOutSecond() * 1000);
////            buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.DEPT_CONFIG_ID.getValue(), mdmConfig);
////            String sendNextPage = soapClient.send(true);
////            JSONObject jsonObjectNextPage = parseResp(sendNextPage);
////            hasNextPage = jsonObjectNextPage.getBool("hasNextPage");
////            log.info("==== 获取全部公司是否有下一页： {} ,当前第 {} 页 ====", hasNextPage, page);
////            allDept.addAll(extractValueList(jsonObjectNextPage));
////        }
////        log.info("==== 获取全部部门完成，总数：{} ====", allDept.size());
//        return allDept;
//    }
//
//    /**
//     * 将 公司 和 组织 合并为对外统一结构 (需要添加参数，在此添加）
//     *
//     * @param subCompanys
//     * @param departments
//     * @return
//     */
//    private static List<JSONObject> convertToOrgInfo(List<JSONObject> subCompanys, List<JSONObject> departments, MdmConfig mdmConfig) {
//        List<JSONObject> orgInfos = new ArrayList<>();
//        for (JSONObject subCompany : subCompanys) {
//            JSONObject orgInfo = new JSONObject();
//            orgInfo.set("orgId", subCompany.getStr("SubcompanyID"));
//            orgInfo.set("orgName", subCompany.getStr("ItemName"));
//            orgInfo.set("orgLevel", subCompany.getStr("level"));
//            orgInfo.set("appOrgPathName", subCompany.getStr("appOrgPath"));
//            orgInfo.set("orgParentId", subCompany.getStr("companyParentId"));
//            orgInfo.set("status", convertOrgStatus(subCompany.getStr("StateEnterprise")));
//            orgInfo.set("order", subCompany.getStr("SortCode"));
//            orgInfo.set("orgCode", subCompany.getStr("SubcompanyID"));
//            log.info("===== company : {} ====", orgInfo);
//            orgInfos.add(orgInfo);
//        }
//
//        for (JSONObject department : departments) {
//            JSONObject orgInfo = new JSONObject();
//            orgInfo.set("orgId", department.getStr("Department_Num"));
//            orgInfo.set("orgName", department.getStr("DepartmentName"));
//            orgInfo.set("orgLevel", department.getStr("level"));
//            orgInfo.set("appOrgPathName", department.getStr("appOrgPath"));
//            //如果父组织的id为0，则使用父分部id
//            String orgParentId = (PullDataConfigEnum.DEPT_PREFIX.getValue() + "0").equals(department.getStr("SuperiorDepartmentID")) ? department.getStr("SubdivisionID") : department.getStr("SuperiorDepartmentID");
//            orgInfo.set("orgParentId", orgParentId);
//            orgInfo.set("status", convertOrgStatus(department.getStr("Dept_State")));
//            orgInfo.set("order", department.getStr("Dept_SortCode"));
//            orgInfo.set("orgCode", department.getStr("Department_Num"));
//            log.info("===== department : {} ====", orgInfo);
//            orgInfos.add(orgInfo);
//        }
//
//        //如果是全量拉取，则过滤掉无效的组织
////        if (mdmConfig.getPullModel().equals(PullDataConfigEnum.FULL.getValue())) {
////            orgInfos = orgInfos.stream().filter(jsonObject -> jsonObject.getStr("status").equals(PullDataConfigEnum.ORG_ENABLE.getValue())).collect(Collectors.toList());
////        }
//
//        List<JSONObject> collect = orgInfos.stream().filter(orgInfo -> StrUtil.isNotEmpty(JSONUtil.parseObj(orgInfo).getStr("orgLevel"))).sorted(Comparator.comparingInt(jsonobj -> JSONUtil.parseObj(jsonobj).getInt("orgLevel"))).collect(Collectors.toList());
//        if (CollUtil.isNotEmpty(collect)) {
//            //组织排序
//            orgInfos = collect;
//        }
//        return orgInfos;
//    }
//
//    private static Integer convertOrgStatus(String deptState) {
//        switch (deptState) {
//            case "11"://正常
//                return 1;
//            case "12"://禁用
//                return 0;
//            case "99"://删除
//                return -1;
//            default:
//                return 1;
//        }
//    }
//
//    /**
//     * 分页查询所有人员基本信息
//     * TODO 人员基本信息不会变动，人员详情会变动,所以如果是增量拉取只增量拉取详情，人员还是要全量
//     *
//     * @return
//     */
//    public static List<JSONObject> getAllUserInfo(MdmConfig mdmConfig) {
//        log.info("==== 分页查询所有人员 start ====");
//        ArrayList<JSONObject> allUser = new ArrayList<>();
////        SoapClient soapClient = SoapClient.create(mdmConfig.getWebServiceTargetUrl())
////                .setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl())
////                .timeout(mdmConfig.getTimeOutSecond() * 1000);
////        int page = 1;
////        buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.USER_CONFIG_ID.getValue(), mdmConfig);
////        String send = soapClient.send(true);
////        JSONObject jsonObject = parseResp(send);
////        allUser.addAll(extractValueList(jsonObject));
////        Boolean hasNextPage = jsonObject.getBool("hasNextPage");
////        log.info("==== 获取全部人员是否有下一页: {} ,当前第: {} 页 , 每页大小: {}====", hasNextPage, page, mdmConfig.getPageSize());
////        while (hasNextPage) {
////            page++;
////            BizException.throwWhenTrueMessage(page > mdmConfig.getLoopMaxThreshold(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrCode(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrMsg() + ":" + mdmConfig.getLoopMaxThreshold());
////            soapClient.reset();
////            soapClient.setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl()).timeout(mdmConfig.getTimeOutSecond() * 1000);
////            buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.USER_CONFIG_ID.getValue(), mdmConfig);
////            String send2 = soapClient.send(true);
////            JSONObject jsonObjectNextPage = parseResp(send2);
////            hasNextPage = jsonObjectNextPage.getBool("hasNextPage");
////            log.info("==== 获取全部人员是否有下一页： {} ,当前第 {} 页 ====", hasNextPage, page);
////            allUser.addAll(extractValueList(jsonObjectNextPage));
////        }
////        log.info("==== 获取全部用户完成，总数：{} ====", allUser.size());
//        return allUser;
//    }
//
//
//    /**
//     * 分页查询所有用户任职详情信息
//     *
//     * @return
//     */
//    public static List<JSONObject> getAllUserDetailInfo(MdmConfig mdmConfig) {
//        log.info("==== 分页查询所有用户任职详情信息 start ====");
//        ArrayList<JSONObject> allUser = new ArrayList<>();
////        SoapClient soapClient = SoapClient.create(mdmConfig.getWebServiceTargetUrl())
////                .setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl())
////                .timeout(mdmConfig.getTimeOutSecond() * 1000);
////        int page = 1;
////        buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.USER_DETAIL_CONFIG_ID.getValue(), mdmConfig);
////        String send = soapClient.send(true);
////        JSONObject jsonObject = parseResp(send);
////        allUser.addAll(extractValueList(jsonObject));
////        Boolean hasNextPage = jsonObject.getBool("hasNextPage");
////        log.info("==== 人员任职详情信息是否有下一页: {} ,当前第: {} 页,  每页大小: {} ====", hasNextPage, page, mdmConfig.getPageSize());
////        while (hasNextPage) {
////            page++;
////            BizException.throwWhenTrueMessage(page > mdmConfig.getLoopMaxThreshold(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrCode(), ErrorEnums.LOOP_MAX_THRESHOLD_VALUE.getErrMsg() + ":" + mdmConfig.getLoopMaxThreshold());
////            soapClient.reset();
////            soapClient.setMethod(ApiEnums.GET_DEPT_LIST_API.getMethodName(), mdmConfig.getNamespaceUrl()).timeout(mdmConfig.getTimeOutSecond() * 1000);
////            buildQueryAllCompanyXml(soapClient, Integer.toString(page), mdmConfig.getPageSize(), PullDataConfigEnum.USER_DETAIL_CONFIG_ID.getValue(), mdmConfig);
////            String send2 = soapClient.send(true);
////            JSONObject jsonObjectNextPage = parseResp(send2);
////            hasNextPage = jsonObjectNextPage.getBool("hasNextPage");
////            log.info("==== 获取用户任职详情信息是否有下一页： {} ,当前第 {} 页 ====", hasNextPage, page);
////            allUser.addAll(extractValueList(jsonObjectNextPage));
////        }
////        log.info("==== 获取全部用户任职详情信息，总数：{} ====", allUser.size());
//        return allUser;
//    }
//
//
//    /**
//     * 构建查询的soapClient
//     * 查询全部公司信息 configId编码： 9900001
//     * 查询全部部门 configId编码： 9900002
//     * 查询全部人员基本信息 configId编码： 9900003
//     * 查询全部人员任职信息 configId编码： 9900004
//     *
//     * @param soapClient
//     * @param page
//     * @param size
//     */
//    private static void buildQueryAllCompanyXml(SoapClient soapClient, String page, String size, String configId, MdmConfig mdmConfig) {
//        SOAPElement tbdTypeBO = null;
//        try {
//            //添加并返回当前节点的引用
//            tbdTypeBO = soapClient.getMethodEle().addChildElement("tbdTypeBO");
//            tbdTypeBO.addChildElement("configId").setValue(configId);
//            tbdTypeBO.addChildElement("queryNameStr").setValue("");
//            tbdTypeBO.addChildElement("queryCreateDateBegin").setValue("");
//            //人员基本信息不受修改动作的影响，所以必须全量 公司也全量
//            if (configId.equals(PullDataConfigEnum.USER_CONFIG_ID.getValue()) || configId.equals(PullDataConfigEnum.COMPANY_CONFIG_ID.getValue())) {
//                tbdTypeBO.addChildElement("queryModifyDateBegin").setValue("");
//            } else {
//                tbdTypeBO.addChildElement("queryModifyDateBegin").setValue(getIncrementDateAfter(mdmConfig));
//            }
//            tbdTypeBO.addChildElement("row").setValue(size);
//            tbdTypeBO.addChildElement("page").setValue(page);
//            SOAPHeader soapHeader = soapClient.getMessage().getSOAPHeader();
//            setAuthHeader(soapHeader, mdmConfig);
//        } catch (SOAPException e) {
//            e.printStackTrace();
//        }
//    }
//
//    private static JSONObject parseResp(String resp) {
//        JSONObject respJsonObj = XML.toJSONObject(resp);
//        return respJsonObj.getJSONObject("soap:Envelope").getJSONObject("soap:Body").getJSONObject("ns2:getTbdMastListPageResponse").getJSONObject("resultRetrun");
//    }
//
//
//    private static String getIncrementDateAfter(MdmConfig mdmConfig) {
////        if (mdmConfig.getPullModel().equals(PullDataConfigEnum.INCRE.getValue())) {
////            return mdmConfig.getIncrementDateAfter();
////        }
//        return StrUtil.EMPTY;
//    }
//
//    /**
//     * 抽取公司响应结果的真实的属性值
//     *
//     * @param jsonObject
//     * @return
//     */
//    private static List<JSONObject> extractValueList(JSONObject jsonObject) {
//        List<JSONObject> jsonObjects = new ArrayList<>();
//        //n个公司对象
//        JSONArray list = jsonObject.getJSONArray("list");
//        if (CollUtil.isNotEmpty(list)) {
//            list.forEach(jsonObj -> {
//                //获取当前公司对象的详情属性值
//                JSONObject detail = JSONUtil.parseObj(jsonObj).getJSONObject("detail");
//                JSONArray valueList = detail.getJSONArray("valueList");
//                JSONObject realJsonObj = new JSONObject();
//                //讲指定的key：value 封装成 jsonObj 中的一个属性值
//                valueList.forEach(obj -> {
//                    JSONObject jsonObjParse = JSONUtil.parseObj(obj);
//                    realJsonObj.set(jsonObjParse.getStr("attrName"), jsonObjParse.getStr("value"));
//                });
//                jsonObjects.add(realJsonObj);
//            });
//        }
//        return jsonObjects;
//    }
//
//    private static void setAuthHeader(SOAPHeader soapHeader, MdmConfig mdmConfig) {
////        try {
////            SOAPElement certificationProxy = soapHeader.addChildElement("CertificationProxy", null, mdmConfig.getNamespaceUrl());
////            certificationProxy.addChildElement("username").setValue(mdmConfig.getUsername());
////            certificationProxy.addChildElement("password").setValue(mdmConfig.getWebsPassword());
////        } catch (SOAPException e) {
////            e.printStackTrace();
////        }
//    }
//
//    /**
//     * 构建公司直接父级id
//     *
//     * @param allCompany
//     */
//    private static void buildParentId(List<JSONObject> allCompany) {
//        for (JSONObject company : allCompany) {
//            System.out.println(company.getStr("ItemName") + "    准备构建父级id");
//            String pid = company.getStr("SuperiorEnterprise");
//            JSONObject parent = allCompany.stream().filter(p -> p.getStr("Enterprise_Num").equals(pid)).findFirst().orElse(null);
//            String subcompanyID = parent.getStr("SubcompanyID");
//            if (StrUtil.isNotEmpty(subcompanyID)) {
//                //如果是顶级组织，则companyParentId为空串
//                if (company.getStr("Enterprise_Num").equals(parent.getStr("Enterprise_Num"))) {
//                    company.set("companyParentId", StrUtil.EMPTY);
//                } else {
//                    company.set("companyParentId", subcompanyID);
//                }
//            }
//        }
//    }
//
//
//    /*
//     * 循环出分部路径以及level
//     * */
//    private static void recursionSub(List<JSONObject> allCompany) {
//        for (JSONObject company : allCompany) {
//            System.out.println(company.getStr("ItemName") + "    寻找父组织");
//            int level = 1;
//            StringBuilder sb = new StringBuilder();
//            sb.append("/").append(company.getStr("ItemName"));
//            String parentId = company.getStr("SuperiorEnterprise");
//            while (StrUtil.isNotEmpty(parentId)) {
//                String pid = parentId;
//                JSONObject parent = allCompany.stream().filter(p -> p.getStr("Enterprise_Num").equals(pid)).findFirst().orElse(null);
//                String subcompanyID = parent.getStr("SubcompanyID");
//                if (parent == null || (PullDataConfigEnum.COMPANY_PREFIX.getValue() + "1").equals(subcompanyID)) {
//                    //如果为根，并且外层 company 与内层找到的 parent 是同一个的话，则推出 （因为数据有一些异常，父id可能为自身的id）
//                    if (!company.getStr("SubcompanyID").equals(subcompanyID)) {
//                        sb.insert(0, "/" + parent.getStr("ItemName"));
//                        level++;
//                    }
//                    break;
//                }
//                sb.insert(0, "/" + parent.getStr("ItemName"));
//                parentId = parent.getStr("SuperiorEnterprise");
//                level++;
//            }
//            company.set("level", level);
//            company.set("appOrgPath", sb.toString());
//            level = 1;
//        }
//    }
//
//
//    public static Integer convertUserStatus(String userStatus, MdmConfig formConfig) {
//        if (StrUtil.isNotEmpty(userStatus)) {
////            Map<String, String> userStatusMapping = formConfig.getAfterProcessUserStatusMapping();
////            switch (userStatusMapping.get(userStatus)) {
////                case "启用":
////                    return UserEnum.Status.ENABLED.getValue();
////                case "停用":
////                    return UserEnum.Status.DISABLED.getValue();
////                case "删除":
////                    return -1;
////                default:
////                    return UserEnum.Status.ENABLED.getValue();
////            }
//        }
//        return 1;
//    }
//
//    /**
//     * 处理出同步人员时,需要排除指定组织下的人员的 组织id (需要包含子组织)
//     *
//     * @param jsonObjects
//     * @param formConfig
//     */
//    public static void syncCacheExcludeOrg(List<JSONObject> jsonObjects, MdmConfig formConfig) {
////        try {
////            if (formConfig.getSyncUserExcludeOrgPathNames().length > 0) {
////                //需要排出的组织路径
////                Set<String> orgPaths = Arrays.stream(formConfig.getSyncUserExcludeOrgPathNames()).collect(Collectors.toSet());
////                if (formConfig.getPullModel().equals(PullDataConfigEnum.FULL.getValue())) {
////                    //如果是全量拉取,则增加过滤缓存
////                    LOCK.lock();
////                    //清除上次缓存的,避免有脏数据
////                    EXCLUDE_ORG_IDS.clear();
////                    //需要排除的组织对象
////                    for (String excludeOrgPath : orgPaths) {
////                        //如果是模糊匹配 ** ,则代表包含任意层级子组织
////                        Set<String> excludeOrgIds = null;
////                        if (excludeOrgPath.endsWith("**")) {
////                            excludeOrgPath = excludeOrgPath.substring(0, excludeOrgPath.indexOf("**") - 1);
////                            String finalExcludeOrgPath = excludeOrgPath;
////                            excludeOrgIds = jsonObjects.stream().filter(jsonObject -> jsonObject.getStr("appOrgPathName").contains(finalExcludeOrgPath)).map(jsonObject -> jsonObject.getStr("orgId")).collect(Collectors.toSet());
////                        } else {
////                            //不是模糊匹配,则全词匹配
////                            String finalExcludeOrgPath1 = excludeOrgPath;
////                            excludeOrgIds = jsonObjects.stream().filter(jsonObject -> jsonObject.getStr("appOrgPathName").equals(finalExcludeOrgPath1)).map(jsonObject -> jsonObject.getStr("orgId")).collect(Collectors.toSet());
////                        }
////                        EXCLUDE_ORG_IDS.addAll(excludeOrgIds);
////                    }
////                } else if (formConfig.getPullModel().equals(PullDataConfigEnum.INCRE.getValue())) {
////                    //如果是增量拉取,并且缓存被清空了(例如重启后缓存被清空,但是配置还是增量)
////                    if (EXCLUDE_ORG_IDS.isEmpty()) {
////                        //从iam数据库加载指定组织下所有的 customunique
////                        IOrgService orgServiceImpl = SpringUtil.getBean("orgServiceImpl", IOrgService.class);
////                        for (String excludeOrgPath : orgPaths) {
////                            Set<String> excludeOrgIds = null;
////                            if (excludeOrgPath.endsWith("**")) {
////                                excludeOrgPath = excludeOrgPath.substring(0, excludeOrgPath.indexOf("**") - 1);
////                                String finalExcludeOrgPath = excludeOrgPath;
////                                List<Org> list = orgServiceImpl.list(new LambdaQueryWrapper<Org>().like(Org::getNamePath, finalExcludeOrgPath));
////                                log.info("iam 查询包含排除组织路径的数据长度: {} , 当前排除路径: {}", list.size(), finalExcludeOrgPath);
////                                excludeOrgIds = list.stream()
////                                        .filter(org -> org.getNamePath().contains(finalExcludeOrgPath))
////                                        .map(Org::getCustomUnique)
////                                        .collect(Collectors.toSet());
////                            } else {
////                                //不是模糊匹配,则全词匹配
////                                String finalExcludeOrgPath1 = excludeOrgPath;
////                                List<Org> list = orgServiceImpl.list(new LambdaQueryWrapper<Org>().eq(Org::getNamePath, finalExcludeOrgPath1));
////                                excludeOrgIds = list.stream()
////                                        .filter(org -> org.getNamePath().contains(finalExcludeOrgPath1))
////                                        .map(Org::getCustomUnique)
////                                        .collect(Collectors.toSet());
////                            }
////                            EXCLUDE_ORG_IDS.addAll(excludeOrgIds);
////                        }
////                    }
////                }
////            }
////        } catch (ClassNotFoundException e) {
////            e.printStackTrace();
////            log.info("获取bean失败 , 无法排除组织", e);
////            throw new BizException("增量拉取,缓存为空,获取orgService bean失败");
////        } finally {
////            LOCK.unlock();
////        }
//    }
//
//
//    public static void main(String[] args) {
//        MdmConfig mdmConfig = new MdmConfig();
////        mdmConfig.setWebServiceTargetUrl("http://192.168.0.77:8098/webservice/BdDataService?wsdl");
////        mdmConfig.setNamespaceUrl("http://bd.invt.com.cn");
////        mdmConfig.setLoopMaxThreshold(80);
////        mdmConfig.setUsername("IAM_SYSTEMUSER");
////        mdmConfig.setWebsPassword("mW2*aF6@");
////        mdmConfig.setTimeOutSecond(300);
////        mdmConfig.setPageSize("300");
////        mdmConfig.setPullModel("FULL");
////        mdmConfig.setIncrementDateAfter("2023-10-10");
////        mdmConfig.setSpecialHandleOrg("914403007362836219:工业自动化事业群;");
////        mdmConfig.setSyncUserExcludeOrgPathNames(new String[]{"/深圳市英威腾电气股份有限公司/深圳市英威腾电动汽车驱动技术有限公司/**"});
////        mdmConfig.setSyncUserIncludeType(new String[]{});
////        List<JSONObject> allSubCompany = getAllCompany(mdmConfig);
////        System.out.println(allSubCompany);
//////        System.out.println(allSubCompany.size());
////        //特殊处理 指定id的公司，去除 Enterprise_Num
////        allSubCompany.stream().filter(jsonObject -> "914403007362836219".
////                        equals(jsonObject.getStr("Enterprise_Num"))
////                        && "工业自动化事业群".equals(jsonObject.getStr("ItemName")))
////                .peek(jsonObject -> {
////                    jsonObject.set("Enterprise_Num", "");
////                }).findFirst();
////
////        buildParentId(allSubCompany);
//////        //处理出分部全路径以及level
////        recursionSub(allSubCompany);
////        System.out.println(allSubCompany);
////        for (JSONObject jsonObject : allSubCompany) {
////            System.out.println(jsonObject.getStr("ItemName") + "            level: " + jsonObject.getStr("level") + "               appOrgPath: " + jsonObject.getStr("appOrgPath") +"            companyParentId: "+jsonObject.getStr("companyParentId"));
////        }
////
////
////        List<JSONObject> allDept = getAllOrg(mdmConfig);
////        System.out.println(allDept.size());
////        AtomicInteger count = new AtomicInteger();
////        allSubCompany.forEach(company -> {
////            //所属当前分部下的所有组织
////            List<JSONObject> belongToCompanyDept = allDept.stream().filter(dept -> dept.getStr("SubdivisionID").equals(company.getStr("SubcompanyID"))).collect(Collectors.toList());
////            System.out.println(" ========== belongToCompanyDept " + company.getStr("ItemName") + " :  " + company.getStr("SubcompanyID") + "=======");
//////            for (JSONObject jsonObject : belongToCompanyDept) {
//////                count.getAndIncrement();
//////                System.out.println(jsonObject.getStr("SubdivisionID"));
//////            }
////
////            //处理出部门全路径以及level
////            recursionDept(belongToCompanyDept, company);
////            for (JSONObject jsonObject : belongToCompanyDept) {
////                System.out.println("===== level: "+jsonObject.getStr("level") +"======= appOrgPath: "+jsonObject.getStr("appOrgPath") +"====== 状态："+(jsonObject.getStr("Dept_State").equals("12")?"停用":"正常"));
////            }
////
////        });
////        System.out.println("========== count : " + count.get());
//
////        List<JSONObject> allOrg = getAllOrg(mdmConfig);
////        System.out.println(allOrg.size());
////        long start = System.currentTimeMillis();
////        System.out.println(" ====================== allUser =================================");
////        List<JSONObject> allUser = getAllUserInfo(mdmConfig);
////        System.out.println(allUser.size());
////        for (JSONObject jsonObject : allUser) {
////            System.out.println(jsonObject);
////        }
//
////        for (int i = 0; i < allUser.size(); i++) {
////            if (i % 2000 == 0){
////                System.out.println("stop");
////            }else {
////                System.out.println(allUser.get(i));
////            }
////        }
//
////        System.out.println("====================  分隔  ===================");
////
////
////        System.out.println(" ====================== allUserDetailInfo =================================");
////        List<JSONObject> allUserDetailInfo = getAllUserDetailInfo(mdmConfig);
////        //将所有用户详情以key为：PersonnelCode 分组
////        Map<String, List<JSONObject>> personnelCode = allUserDetailInfo.stream().collect(Collectors.groupingBy(jsonObject -> jsonObject.getStr("PersonnelCode")));
////        System.out.println(personnelCode.size());
////
////        personnelCode.forEach((k,v)->{
////            System.out.println("===== k:"+ k  + " ====== v: "+v);
////
////
////        });
//
////        for (JSONObject jsonObject : allUser) {
////            System.out.println("=== " + jsonObject);
////        }
//
////        List<JSONObject> personnelStatu = allUser.stream().filter(jsonObject -> {
////            return StrUtil.isEmpty(jsonObject.getStr("PersonnelStatu"));
////        }).collect(Collectors.toList());
////        System.out.println(personnelStatu);
//
//
////        long end = System.currentTimeMillis();
////        System.out.println(end - start);
//
////        System.out.println(allUserDetailInfo.size());
////        for (int i = 0; i < allUserDetailInfo.size(); i++) {
////            if (i % 2000 == 0) {
////                System.out.println("stop");
////            } else {
////                System.out.println(allUserDetailInfo.get(i));
////            }
////        }
//
////        List<JSONObject> allUser = getAllUser(mdmConfig);
////        System.out.println(allUser);
//    }
//}
